<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>聊天记录</title>
    <link rel="stylesheet" href="/static/layim-v3.7.6/src/css/layui.css">
    <style>
        body .layim-chat-main {
            height: auto;
        }
    </style>
</head>
<body>

<div class="layim-chat-main">
    <ul id="LAY_view"></ul>
</div>
<div id="LAY_page" style="margin: 0 10px;"></div>
<textarea title="消息模版" id="LAY_tpl" style="display:none;">
{{# layui.each(d.data, function(index, item){
  if(item.id == parent.layui.layim.cache().mine.id){ }}
    <li class="layim-chat-mine">
        <div class="layim-chat-user">
            <img src="{{ item.avatar }}">
            <cite>
                <i>{{ layui.data.date(item.create_at) }}</i>
                {{ item.username }}
            </cite>
        </div>
        <div class="layim-chat-text">
            {{ layui.layim.content(item.content) }}
        </div>
    </li>
  {{# } else { }}
    <li>
        <div class="layim-chat-user">
            <img src="{{ item.avatar }}">
            <cite>
                {{ item.username }}
                <i>{{ layui.data.date(item.create_at) }}</i>
            </cite>
        </div>
        <div class="layim-chat-text">
            {{ layui.layim.content(item.content) }}
        </div>
    </li>
  {{# }
}); }}
</textarea>

<script src="/static/layim-v3.7.6/src/layui.js"></script>
<script>
layui.use(['layim', 'laypage'], function () {
    let layim = layui.layim
        , laytpl = layui.laytpl
        , $ = layui.jquery
        , laypage = layui.laypage;

    let getQueryStringArgs = function() {
        // 取得没有开头问号的查询字符串
        let qs = (location.search.length > 0 ? location.search.substring(1) : ""),
            // 保存数据的对象
            args = {};
        // 把每个参数添加到 args 对象
        for (let item of qs.split("&").map(kv => kv.split("="))) {
            let name = decodeURIComponent(item[0]),
                value = decodeURIComponent(item[1]);
            if (name.length) {
                args[name] = value;
            }
        }
        return args;
    }

    let args = getQueryStringArgs();

    layui.jquery.post("/user/chatlog",{id:args.id,type:args.type,page:1},function (res) {
        let html = laytpl(LAY_tpl.value).render({
            data: res.data
        });
        $('#LAY_view').html(html);
    }, "json")
});
</script>
</body>
</html>